/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.vijay.mvnbuilddownload;

import org.w3c.dom.*;
import org.xml.sax.*;
import javax.xml.parsers.*;
/**
 *
 * @author elangovanv
 */
public class Metadata {
    private String groupId;
    private String artifactId;
    private String version;

    private NodeList nodeList;

    private MetadataVersioning versioning;

    public Metadata(NodeList nodeList) {
        this.nodeList=nodeList;
    }

/*
<metadata>
<groupId>com.dnb.dnbi.creditCommon</groupId>
<artifactId>dnbi-creditCommon-assembly</artifactId>
<version>9.0.8-SNAPSHOT</version>
?
<versioning>
?
<snapshot>
<timestamp>20101215.010239</timestamp>
<buildNumber>1</buildNumber>
</snapshot>
<lastUpdated>20101215010344</lastUpdated>
</versioning>
</metadata>
 */
    public void parse() {
        for (int i = 0; i < nodeList.getLength(); i++) {
            Node node = nodeList.item(i);

            if (node.getNodeType() == Node.ELEMENT_NODE && node.getNodeName().equals("groupId")) {
                this.groupId=node.getTextContent();
                //System.out.println(this.groupId);
            } else if (node.getNodeType() == Node.ELEMENT_NODE && node.getNodeName().equals("artifactId")) {
                this.artifactId=node.getTextContent();
            } else if (node.getNodeType() == Node.ELEMENT_NODE && node.getNodeName().equals("version")) {
                this.version=node.getTextContent();
            } else if (node.getNodeType() == Node.ELEMENT_NODE && ((Element) node).getTagName().equals("versioning")) {
                this.versioning=new MetadataVersioning(((Element) node).getChildNodes());
                this.versioning.parse();
            }
        }
        
    }

    public String getArtifactId() {
        return artifactId;
    }

    public void setArtifactId(String artifactId) {
        this.artifactId = artifactId;
    }

    public String getGroupId() {
        return groupId;
    }

    public void setGroupId(String groupId) {
        this.groupId = groupId;
    }

    public String getVersion() {
        return version;
    }

    public void setVersion(String version) {
        this.version = version;
    }

    public MetadataVersioning getVersioning() {
        return versioning;
    }

    public void setVersioning(MetadataVersioning versioning) {
        this.versioning = versioning;
    }

    public String toString() {
        return "Metadata{" + "groupId=" + groupId + "artifactId=" + artifactId + "version=" + version + "versioning=" + versioning + '}';
    }


}
